home *** CD-ROM | disk | FTP | other *** search
- #include <SetUpA4.h>
-
- static char unites[10][8] = { "zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine " } ;
- static char dizaines[10][14] = { "","ten ","twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety " } ;
- static char multiples[4][9] = { "hundred","thousand","million" ,"billion"} ;
- static char special[10][11] = { "and ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "} ;
-
- char *strcpy(char *s1,char *s2) ;
- char *strcat(char *s1,char *s2) ;
- void reverse(char *s) ;
- short strlen(char *s) ;
- short english(char *temp,char *tmpresult,short n) ;
-
- pascal void main(char *text,char *result)
- {
- char thestring[20],temp[4],tmpresult[256];
- short i,j,l,res ;
- short plurial ;
-
- RememberA0() ;
- SetUpA4() ;
- text[12] = 0 ; /* max = 999 999 999 999 */
- result[0] = '\0' ;
- strcpy(thestring,text) ;
- if( strlen(thestring) != 0 )
- {
- while (thestring[0] == '0')
- for (i=0;thestring[i]!=0;thestring[i]=thestring[i+1],i++) ;
- plurial = 0 ;
- if ( (l = strlen(thestring)) )
- {
- reverse(thestring) ;
- if (l < 12)
- {
- for ( i=l ; i<12 ; i++ )
- thestring[i] = '0' ;
- thestring[12] = 0 ;
- }
- for ( i=3 ; i>=0 ; i--)
- {
- for ( j=3*i ; j<3*(i+1) ; j++)
- temp[j-3*i] = thestring[j] ;
- temp[3] = 0 ;
- tmpresult[0] = 0 ;
- res = english(temp,tmpresult,i) ;
- if ( (res > 1) || ((res == 1) && (i != 0)) )
- plurial = 1 ;
- strcat(result,tmpresult) ;
- }
- }
- else
- strcpy(result,unites[0]) ;
- }
- RestoreA4() ;
- }
-
- short english(char *temp,char *tmpresult,short n)
- {
- register int res,x,y,z;
-
- reverse(temp);
- x = temp[0]-'0' ;
- y = temp[1]-'0' ;
- z = temp[2]-'0' ;
- res = ((x*10)+y)*10+z;
- if(res!=0)
- {
- if(x)
- {
- strcpy(tmpresult,unites[x]);
- strcat(tmpresult,multiples[0]);
- strcat(tmpresult," ");
- }
- if(y>1)
- {
- strcat(tmpresult,dizaines[y]);
- }
- if(z)
- if(y==1)
- strcat(tmpresult,special[z]);
- else
- {
- if ( (z != 1) || (x != 0) || (y != 0) || (res == 1) )
- strcat(tmpresult,unites[z]);
- }
- else
- if(y==1)
- strcat(tmpresult,dizaines[1]);
- if (res && n)
- strcat(tmpresult,multiples[n]) ;
- if ((res>1) &&(n>1))
- strcat(tmpresult,"s");
- if (res &&(n>0))
- strcat(tmpresult," ");
- }
- }
-
- char * strcpy(char *s1,char *s2)
- {
- asm {
- movea.l s1,a0 ; A0 = s1
- movea.l s2,a1 ; A1 = s2
- move.l a0,d0 ; D0.L = result
- @1 move.b (a1)+,(a0)+
- bne.s @1
- }
- }
-
-
- char *strcat(char *s1,char *s2)
- {
- asm {
- movea.l s1,a0 ; A0 = s1
- movea.l s2,a1 ; A1 = s2
- move.l a0,d0 ; D0.L = result
- @1 tst.b (a0)+
- bne.s @1
- subq.l #1,a0
- @2 move.b (a1)+,(a0)+
- bne.s @2
- }
- }
-
- short strlen(char *s)
- {
- asm {
- moveq #-1,d0 ; D0.L = result
- movea.l s,a0 ; A0 = s
- @1 addq.l #1,d0
- tst.b (a0)+
- bne.s @1
- }
- }
-
- void reverse(char *s)
- {
- register short i,j ;
- register char c ;
-
- for(i=0,j=strlen(s)-1;i<j;i++,j--)
- {
- c = s[j] ;
- s[j] = s[i] ;
- s[i] = c ;
- }
- }
-